/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package samoloty.view;

import Utils.MyOwnFocusTraversalPolicy;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.LayoutManager;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.plaf.basic.BasicComboBoxUI.ComboBoxLayoutManager;
import javax.swing.plaf.basic.BasicScrollBarUI;
import javax.swing.plaf.basic.BasicSplitPaneUI.BasicVerticalLayoutManager;
import samoloty.model.IDataModel;

/**
 *
 * @author borysfan
 */
public class AcRegPanel extends ContentPanel {

    private MyLabel title;
    private ArrayList<JButton> buttons;
    private Vector<Component> focusOrder;
    private MyOwnFocusTraversalPolicy travelsalPolicy;
    private JScrollPane scroll;
    private ContentPanel panel;

    public AcRegPanel() {
        buttons = new ArrayList<JButton>();
    }

    public void addTitle(String name) {
        title = new MyLabel(name);
        title.setBold();
        title.setAlignmentX(CENTER_ALIGNMENT);
        panel.add(title);
    }

    public void addSubTitle(String subTitle) {
        MyLabel lab = new MyLabel(subTitle);
        lab.setBold();
        lab.setAlignmentX(CENTER_ALIGNMENT);
        panel.add(lab);
    }

    public void insertVerticalSeparator(int space) {
        panel.add(Box.createRigidArea(new Dimension(0, space)));
    }

    public MyButton addButton(String name, IDataModel data, int btnHeight) {
        MyButton btn = new MyButton(name, 300, btnHeight);
        panel.add(btn);
        buttons.add(btn);
        return btn;
    }

    public void setFirstFocused() {
        if (buttons.size() > 0) {
            buttons.get(0).requestFocus();
        }
    }

    public void firstFocused() {
        buttons.get(0).requestFocus();
    }

    public void setTravelStart() {
        focusOrder = new Vector<Component>();
    }

    public void setTravelStop() {
        travelsalPolicy = new MyOwnFocusTraversalPolicy(focusOrder);
        this.setFocusTraversalPolicy(travelsalPolicy);
        this.setFocusTraversalPolicyProvider(true);
        this.setFocusCycleRoot(true);
    }

    public void addButtonToTravel(MyButton a) {
        focusOrder.add(a);
    }

    public void initScroll() {
        panel = new ContentPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
        panel.setBorder(null);
        scroll = new JScrollPane(panel);
        panel.setPreferredSize(new Dimension(500, 1100));
        scroll.getVerticalScrollBar().setUnitIncrement(10);
        scroll.setBorder(null);
        scroll.setBackground(MyColors.getBlack());
        scroll.setBounds(2, 2, this.getWidth() - 4, this.getHeight() - 4);
        add(scroll);
    }
}
